<?php
namespace app\model;

use think\Model;

class Banner extends Model
{
    protected $append = [
        'position_txt'
    ];
    public function getPositionTxtAttr($value,$data){
        $positionData = $this->getPosition();
        if($data['position']!=0){
            return $positionData[$data['position']];
        }else{
            return '-';
        }
    }
    public function getThumbAttr($value, $data)
    {
        $_module = request()->module();
        if($_module == 'api'){
            $host = request()->domain();
            return $host.$value;

        }else{
            return $value;
        }
    }

    public function getAllBanner(){
        $positionArr = $this->getPosition();
        $bannerArr = $this->where("id",'>',0)->select();
        $bannerData = [];
        foreach ($positionArr as $po_id => $value){
            foreach ($bannerArr as $item){
                if($po_id == $item['position']){

                    $bannerData[$po_id] = $item;
                }
            }
            if(!isset($bannerData[$po_id])){
                $bannerData[$po_id] = ['thumb'=>'','name_en'=>'','name_hk'=>'','name_zh'=>''];
            }
        }
        return $bannerData;

    }
    public function getPosition(){
        return [
            1=>__('position_pc'),
            2=>__('position_mobile'),
            3=>__('position_hj1'),
            4=>__('position_hj2'),
            5=>__('position_hj3'),
            6=>__('position_gzs1'),
            7=>__('position_gzs2'),
            8=>__('position_gzs3'),
            9=>__('position_gzs4'),
            10=>__('our_studio'),
            11=>__('Our Story'),
        ];
    }
}
